﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace WMI.NET.CIM
{
    /// <summary>
    /// The CIM_NetworkAdapter class is an abstract class that defines general networking hardware concepts (for example, permanent address or speed of operation). The information is conveyed using the CIM_DeviceSAPImplementation association.
    /// Network adapters and related endpoints represent the potential for connectivity among peers. The potential for connectivity is significantly different from the master or subordinate and controller or controlled-by relationships of CIM_Controller. Occasionally, however, a single device acts as both a network adapter and a controller, for example, when a fiber channel adapter operates as a computer system's SCSI controller. In which case, aspects of the device are network oriented and others are controller oriented. The controller and adapter classes should be instantiated and a device identity relationship should also be created to link the different aspects of the device.
    /// </summary>
    public class CIM_NetworkAdapter : CIM_LogicalDevice
    {

        private Nullable<Boolean> _AutoSense;
        private Nullable<UInt64> _MaxSpeed;
        private string[] _NetworkAddresses;
        private string _PermanentAddress;
        private Nullable<UInt64> _Speed;

        /// <summary>
        /// If TRUE, the network adapter can automatically determine the speed or other communications characteristics of the attached network media.
        /// </summary>
        public Nullable<Boolean> AutoSense { get { return _AutoSense; } }

        /// <summary>
        /// Maximum speed, in bits per second (BPS), for the network adapter.
        /// </summary>
        public Nullable<UInt64> MaxSpeed { get { return _MaxSpeed; } }

        /// <summary>
        /// List of network addresses for an adapter.
        /// </summary>
        public string[] NetworkAddresses { get { return _NetworkAddresses; } }

        /// <summary>
        /// Network address hard-coded into an adapter. The hard-coded address can be changed with a firmware upgrade or software configuration. If changed, the field should be updated when the change is made. This property should be left blank if no hard-coded address exists for the network adapter.
        /// </summary>
        public string PermanentAddress { get { return _PermanentAddress; } }

        /// <summary>
        /// Estimate of the current bandwidth, in BPS. For endpoints that vary in bandwidth or for those where no accurate estimation can be made, this property should contain the nominal bandwidth.
        /// </summary>
        public Nullable<UInt64> Speed { get { return _Speed; } }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public CIM_NetworkAdapter(ManagementBaseObject mbo)
            : base(mbo)
        {
            _AutoSense = mbo.GetBoolValue("AutoSense");
            _MaxSpeed = mbo.GetUlongValue("MaxSpeed");
            _NetworkAddresses = mbo.GetStringValueArray("NetworkAddresses");
            _PermanentAddress = mbo.GetStringValue("PermanentAddress");
            _Speed = mbo.GetUlongValue("Speed");
        }

    }
}
